<template>
  <div class="fight">
    <div class="teamArr">
    <el-row :gutter="16">
      <el-col v-for="(team,index) in fightArr" :span="8" :key="index">
    <!-- <el-card  class="teamList"> -->
      <div class="teamList" @click="showMeng(team)">
      {{team.offense}} 
      <img :src="pageSrc.vsImg" class="vsImg">
       {{team.defender}} 
      </div>
      </el-col>
    </el-row>
  </div>
    <el-row :gutter="20">
      <el-col :span="12" v-for="i in 2" :key="i">
        <el-card class="card-color">
          <div slot="header" class="clearfix">
            <span>{{i==1?'进取组':'榜样组'}}</span>
            </div>
            <div class="subArr">
          <div 
          v-for="(o,index) in (i===1?offenseArr:defenderArr)" 
          :key="o" 
          class="sub subList" 
          :class="index===(i===1?fightTemp.index.o:fightTemp.index.d)?'active':''"
          @click="setFight(i-1,o,index)">
            {{o}}
          </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <div class="tempTeam">
      <div class="vs">{{fightTemp.offense?fightTemp.offense:'等待选择'}} vs {{fightTemp.defender?fightTemp.defender:'等待选择'}}</div>
      <el-button @click="mateTeam" type="danger" plain>PK</el-button>
    </div>
    <div @click="showMeng(null)">
    <Meng :teamData="mengData"  v-if="mengData!==null"></Meng>
    </div>
  </div>
</template>

<script>
import vsImg from "@/assets/img/vs.png";
import Meng from "@/components/meng";
export default {
  name: "fight",
  data() {
    return {
      pageSrc: {
        vsImg
      },
      offenseArr: [
        "龙奥支行",
        "甸柳支行",
        "文西支行",
        "历山东路支行",
        "山大路支行",
        "浆水泉支行",
        "分行营业部",
        "开元支行",
        "泺源大街支行"
      ],
      defenderArr: [
        "二环东路支行",
        "花园支行",
        "解放路支行",
        "朝山街支行",
        "燕山支行",
        "文东支行",
        "大明湖支行",
        "明湖东路支行",
        "工业南路支行"
      ],
      fightTemp: {
        offense: null,
        defender: null,
        index: { o: null, d: null }
      },
      fightArr: new Array(),
      mengData: null
    };
  },
  components: {
    Meng
  },
  methods: {
    setFight(a, o, i) {
      // a=0则为进攻方
      if (a === 0) {
        this.fightTemp.offense = o;
        this.fightTemp.index.o = i;
      } else {
        this.fightTemp.index.d = i;
        this.fightTemp.defender = o;
      }
    },
    mateTeam() {
      if (
        this.fightArr.length < 9 &&
        this.fightTemp.offense !== null &&
        this.fightTemp.defender !== null
      ) {
        let obj = JSON.parse(JSON.stringify(this.fightTemp));
        this.fightArr.push(obj);
        this.offenseArr.splice(obj.index.o, 1);
        this.defenderArr.splice(obj.index.d, 1);
        this.showMeng(obj);

        this.fightTemp = {
          offense: null,
          defender: null,
          index: { o: null, d: null }
        };
      } else {
        this.$alert("请确定检查双方阵容", "错误", {
          confirmButtonText: "返回"
        });
      }
    },
    showMeng(d) {
      this.mengData = d;
      console.log(1);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.subArr {
  max-height: 300px;
  overflow: auto;
  .subList {
    padding: 0.8em;
    transition: background-color 0.5s;
    border-radius: 3px;
    &:hover {
      background-color: rgba(255, 0, 0, 0.336);
    }
    &.active {
      background-color: rgba(0, 110, 255, 0.336);
    }
  }
}
.teamArr {
  margin-bottom: 1em;
  .teamList {
    text-align: center;
    border-radius: 4px;
    // overflow: hidden;
    margin: 0 0 10px 0;
    // padding-top:5px;
    // padding-bottom: 5px;
    height: 3em;
    line-height: 3em;
    background-color: rgba(139, 11, 11, 0.637);
    // border: 1px solid #ebeef5;
    box-shadow: 0 0 20px rgba(139, 11, 11, 0.637);
    transition: all 0.8s;
    color: #fff;
    &:hover {
      background-color: rgba(153, 42, 42, 0.637);
      transform: scale(1.1);
      img {
        transform: scale(1.5);
        transition: transform 0.8s;
      }
    }
    // box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    // color: #303133;
  }
}
.vsImg {
  height: 3em;
  margin: 0 1em;
  vertical-align: top;
}
.tempTeam {
  display: flex;
  flex-flow: column;
  justify-content: center;
  .vs {
    text-align: center;
    margin: 20px 0;
    font-size: 2rem;
    color: #ffffff;
    text-shadow: 0 0 5px #000;
  }
}
</style>
